from scrapy.crawler import CrawlerProcess
from viewtags.spiders.Viewtags import ViewTags
from scrapy.utils.project import get_project_settings
from apscheduler.schedulers.twisted import TwistedScheduler

try:
    # 读取setting配置文件
    process = CrawlerProcess(get_project_settings())
    sched = TwistedScheduler()
    # 添加作业，每天3点执行一次
    # sched.add_job(process.crawl, 'interval', args=[ViewTags],seconds=5*60)
    sched.add_job(process.crawl, 'cron', args=[ViewTags], day='*', hour='03', minute='00')
    sched.start()
    process.start(False)
except(KeyboardInterrupt, SystemExit):
    sched.shutdown()
    print('Exit The Job!')
